﻿#region

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BuXiaChu.OrderDishes.Model;
using BuXiaChu.OrderDishes.DAL;

#endregion

namespace BuXiaChu.OrderDishes.BLL
{
    public class OrderInfoManager
    {
        /// <summary>
        /// Insert Or Update
        /// </summary>
        public static bool Save(OrderInfoModel obj, List<OrderItemModel> orderItemList)
        {
            return OrderInfoDAL.Save(obj, orderItemList);
        }

        public static OrderInfoModel GetByOrderInfoId(decimal orderCode)
        {
            return OrderInfoDAL.GetByOrderInfoId(orderCode);
        }

        public static List<OrderInfoModel> Search(string sqlWhere, int pageIndex, int pageSize, out int pageCount)
        {
            return OrderInfoDAL.Search(sqlWhere, pageIndex, pageSize, out pageCount);
        }

        public static List<OrderItemModel> GetOrderItemListBy(long orderId)
        {
            var pageCount = 0;
            var sqlWhere = " OrderInfoId = " + orderId.ToString();
            Dictionary<long, List<OrderItemModel>> result = SearchOrderItem(sqlWhere, 0, 0, out pageCount);
            if (result.Count > 0) {
                return result[orderId];
            }
            return new List<OrderItemModel>();
        }

        public static Dictionary<long, List<OrderItemModel>> SearchOrderItem(string sqlWhere, int pageIndex, int pageSize, out int pageCount)
        {
            return OrderItemDAL.Search(sqlWhere, pageIndex, pageSize, out pageCount);
        }
    }
}
